package com.happy.mycar.ui.MyCar;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.happy.mycar.CBLEDevice;
import com.happy.mycar.R;
import com.happy.mycar.databinding.FragmentMycarBinding;

public class MyCarFragment extends Fragment {

    private FragmentMycarBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        binding = FragmentMycarBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        root.findViewById(R.id.btn_unlock).setOnClickListener(v -> {
            CBLEDevice.getInstance().unlockCar();
        });
        root.findViewById(R.id.btn_lock).setOnClickListener(v-> {
            CBLEDevice.getInstance().lockCar();
        });

        root.findViewById(R.id.btn_open_trunk).setOnClickListener(v-> {
            CBLEDevice.getInstance().trunkCar();
        });

        CBLEDevice.getInstance().setContext(requireContext(), (TextView) root.findViewById(R.id.connectionStatus));
        return root;
    }

    @Override
    public void onDestroyView() {
        CBLEDevice.getInstance().setLogTextView(null);
        super.onDestroyView();
        binding = null;
    }
}